package com.br.sae.model.dao;

import java.util.List;

import javax.persistence.Query;

import com.br.sae.conexaobd.SistemaDAO;
import com.br.sae.model.entitys.Disciplina;

public class DisciplinaBD {

	public List<Disciplina> consultaDisciplina() {
		String sql = "SELECT disciplina FROM Disciplina disciplina";
		Query query = SistemaDAO.createQuery(sql);
		return query.getResultList();
	}

	public List<Disciplina> consultaDisciplina(String nome) {
		String sql = "SELECT disciplina FROM Disciplina disciplina WHERE disciplina.nome= :nome";
		Query query = SistemaDAO.createQuery(sql);
		query.setParameter("nome", nome);
		return query.getResultList();
	}

	public boolean incluirDisciplina(Disciplina disciplina) {
		try {
			SistemaDAO.persistDisciplina(disciplina);
			return true;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return false;
	}

	public boolean alterarDisciplina(Disciplina disciplina) {
		try {
			SistemaDAO.updateDisciplina(disciplina);
			return true;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return false;
	}

	public boolean removerDisciplina(Disciplina disciplina) {
		try {
			SistemaDAO.removerDisciplina(disciplina);
			return true;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return false;
	}

}
